home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 90 / CDMM_90_1.ISO / Cycling Manager 2 / CyclingManager2Demo.exe / Disk1 / data1.cab / Game / DataCM2 / MenuServer / Phase.cnc < prev    next >
Encoding:
Text File  |  2002-05-10  |  4.2 KB  |  173 lines

  1.  
  2. // Inform Clients that race has started
  3. func void NotifyRaceStart()
  4. {
  5.     var Gui_Component pComponent;
  6.     var CGuestUser pdtData;
  7.         
  8.     var Net_Client pClient;
  9.     var i32x i,iNumClients;
  10.     var i32x iUserId;
  11.     var i32x irteamid;
  12.  
  13.     // get client list
  14.     iNumClients = GetComponentNumber(g_pAncestorComponent);
  15.     
  16.     i=0;
  17.     print("MS : Notify Race start...\n");
  18.     print("###Warning Not all clients have to join the race !!!\n");
  19.     while(i<iNumClients)
  20.     {
  21.         pComponent = GetComponent( g_pAncestorComponent, i);        
  22.         if (pComponent)
  23.         {
  24.             pdtData = GetPrimaryData( pComponent);        
  25.             iUserId = pdtData.m_iUserId;
  26.             pClient = pdtData.m_pClient;
  27.             
  28.             
  29.             irteamid = Join_GetIntFromKey( g_stJoins.m_iUser_iPreRaceTeamId, iUserId);
  30.             if (irteamid>=0)
  31.             {
  32.                 print("\tClient:"+ Join_GetStringFromKey(g_stJoins.m_iUser_szLogin,iUserId) + " Id :"+itoa(iUserId)+"\n");
  33.                 pClient<<  mUser_InRaceStart(irteamid);
  34.                 pClient << mUser_ForceRace();
  35.             }
  36.         }
  37.         i=i+1;
  38.     }
  39. }
  40.  
  41. // Inform Clients that race has stopped
  42. func void NotifyRaceStop()
  43. {    
  44.     var Gui_Component pComponent;
  45.     var CGuestUser pdtData;
  46.  
  47.     var i32x i,iNumClients;
  48.     var Net_Client pClient;
  49.     
  50.     // get client list
  51.     iNumClients = GetComponentNumber(g_pAncestorComponent);
  52.     
  53.     // Inform Client that resolution server is stopped
  54.     i=0;
  55.     while(i<iNumClients)
  56.     {
  57.         pComponent = GetComponent( g_pAncestorComponent, i);
  58.         if (pComponent)
  59.         {
  60.             pdtData = GetPrimaryData( pComponent);        
  61.             pClient = pdtData.m_pClient;
  62.             
  63.             pClient<<  mUser_InRaceStop();
  64.         }
  65.         i=i+1;
  66.     }
  67. }
  68.  
  69.  
  70. // *** Inform all clients of phase change ***
  71. func void NotifyEndOfGameMode()
  72. {
  73.     var Gui_Component pComponent;
  74.     var CGuestUser pdtData;
  75.  
  76.     var i32x i;
  77.     var Net_Client pClient;
  78.     var i32x iNumClients,iLastStageID;
  79.  
  80.     // Last Stage Raced
  81.     iLastStageID = GetLastStageID();
  82.     
  83.     iNumClients = GetComponentNumber(g_pAncestorComponent);
  84.     i=0;
  85.     while(i<iNumClients)
  86.     {
  87.         pComponent = GetComponent( g_pAncestorComponent, i);
  88.         if (pComponent)
  89.         {
  90.             pdtData = GetPrimaryData( pComponent);        
  91.             pClient = pdtData.m_pClient;
  92.             
  93.             pClient << mEndOfGameMode(iLastStageID);
  94.         }
  95.         i = i+1;
  96.     }
  97. }
  98.  
  99. func void PrepareForRace()
  100. {
  101.     var Gui_Component pComponent;
  102.     var CGuestUser pdtData;
  103.  
  104.     var CInRaceUser pdtInRaceData;
  105.  
  106.     // Current phase is now the in race phase
  107.     print("MS : Prepare To Race:\n");
  108.     println("\tRaceId:"+itoa(GetCurrentRaceID()));
  109.     println("\tStageId:"+itoa(GetCurrentStageID()));
  110.     println("\tDay:"+itoa(GetCurrentDay()));
  111.  
  112.     //mao debug compute tactics for the race
  113.     GenerateRaceRatings();
  114.     
  115.     // Send PreRace data to resolution server
  116.     CreateInRaceServer(g_iInRaceServerPort);
  117.     
  118.  
  119.     // Set the new interface for each client connected
  120.     var i32x i;
  121.     var Net_Client pClient;
  122.     var i32x iNumClients;
  123.     var i32x iUserId;
  124.     var i32x iTeamId;
  125.     var i32x iPreRaceTeamId;
  126.     
  127.     
  128.     print("MS : Inform clients of race start:\n");
  129.     i=0;
  130.     iNumClients = GetComponentNumber(g_pAncestorComponent);
  131.     println("num clients : "+ itoa(iNumClients));
  132.  
  133.     while(i<iNumClients)
  134.     {
  135.         pComponent = GetComponent( g_pAncestorComponent, i);
  136.         if (pComponent)
  137.         {
  138.             pdtData = GetPrimaryData( pComponent);
  139.             iUserId = pdtData.m_iUserId;
  140.             pClient = pdtData.m_pClient;
  141.  
  142.             // add inrace interface
  143.             pdtInRaceData = new CInRaceUser;
  144.             AddInterface(pComponent,iInRace,pdtInRaceData);
  145.             
  146.             // Add the client to the RServer
  147.             iTeamId            = Join_GetIntFromKey(g_stJoins.m_iUser_iTeamId,    iUserId);
  148.             iPreRaceTeamId    = Join_GetIntFromKey(g_stJoins.m_iUser_iPreRaceTeamId, iUserId);    
  149.             if(iPreRaceTeamId == -1)
  150.             {
  151.                 // User team is not register for race
  152.                 println("\tUser "+Join_GetStringFromKey(g_stJoins.m_iUser_szLogin,iUserId)+" not in race with team "+Join_GetStringFromKey(g_stJoins.m_iTeam_szName,iTeamId));
  153.             }
  154.             else
  155.             {            
  156.                 // Send to the client the RServer IP and port
  157.                 println("\tUser "+Join_GetStringFromKey(g_stJoins.m_iUser_szLogin,iUserId)+" in race with team "+Join_GetStringFromKey(g_stJoins.m_iTeam_szName,iTeamId));
  158.                 println("\t\tPreRaceId:"+itoa(iPreRaceTeamId));
  159.             }
  160.         }
  161.         i = i+1;
  162.     }
  163.  
  164.     // synchronize db
  165.     Database_SendSynchronization(DATABASE_SERVER);
  166.  
  167.     // notify Launch race
  168.     LaunchRace(0,SendEvent,SendInterface);
  169.  
  170.     NotifyRaceStart();
  171. }
  172.  
  173.